package com.bng8.majunzhu.admin.web.system.controller;

import org.commonmark.node.Node;
import org.commonmark.parser.Parser;
import org.commonmark.renderer.html.HtmlRenderer;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class MarkdownController {

    private final Parser parser = Parser.builder().build();
    private final HtmlRenderer renderer = HtmlRenderer.builder().build();

    @PostMapping("/convert")
    public String convertMarkdownToHtml(@RequestBody String markdown) {
        Node document = parser.parse(markdown);
        return renderer.render(document);
    }
}
